//
//  ZZCDynamicTableViewCell.m
//  B段项目
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCDynamicTableViewCell.h"

@interface ZZCDynamicTableViewCell ()

@property (nonatomic, retain)UIImageView *headImageView;
@property (nonatomic, retain)UILabel *nameLabel;
@property (nonatomic, retain)UILabel *contentLabel;
@property (nonatomic, retain)UILabel *timeLabel;

@property (nonatomic, retain)UILabel *markLabel;
@property (nonatomic, retain)UILabel *markCountLabel;
@property (nonatomic, retain)UIImageView *commentImageView;
@property (nonatomic, retain)UILabel *commentLabel;
@property (nonatomic, retain)UIImageView *likeImageView;
@property (nonatomic, retain)UILabel *likeLabel;

@end

@implementation ZZCDynamicTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width / 18, HEIGHT / 25, self.contentView.frame.size.width / 10, self.contentView.frame.size.width / 10)];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = self.headImageView.frame.size.width / 2;
    self.headImageView.layer.borderWidth = 0;
    self.headImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self.contentView addSubview:self.headImageView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headImageView.frame.origin.x + self.headImageView.frame.size.width + WIDTH * 0.023, self.headImageView.frame.origin.y + HEIGHT * 0.01, WIDTH / 2, self.headImageView.frame.size.height - HEIGHT * 0.01 * 2)];
    self.nameLabel.textColor = [UIColor colorWithRed:0.34 green:0.41 blue:0.52 alpha:1];
    self.nameLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headImageView.frame.origin.x + self.headImageView.frame.size.width + WIDTH / 1.6, self.nameLabel.frame.origin.y, self.nameLabel.frame.size.width, self.nameLabel.frame.size.height)];
    self.timeLabel.textColor = [UIColor colorWithRed:0.76 green:0.76 blue:0.76 alpha:1];
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:self.timeLabel];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headImageView.frame.origin.x, self.headImageView.frame.origin.y + self.headImageView.frame.size.height + HEIGHT * 0.04, WIDTH - self.headImageView.frame.origin.x * 2, HEIGHT * 0.05)];
    self.contentLabel.textColor = [UIColor colorWithRed:0.45 green:0.45 blue:0.45 alpha:1];
    self.contentLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.contentLabel];
    
    
    self.markImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.contentLabel.frame.origin.x, self.contentLabel.frame.origin.y + self.contentLabel.frame.size.height + HEIGHT / 25, self.contentView.frame.size.width / 21, self.contentView.frame.size.width / 21)];
    self.markImageView.image = [UIImage imageNamed:@"iconfont-biaoqian.png"];
    [self.contentView addSubview:self.markImageView];
    
    self.markLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.markImageView.frame.origin.x + self.markImageView.frame.size.width + self.contentView.frame.size.width / 100, self.markImageView.frame.origin.y, self.contentView.frame.size.width / 5, self.markImageView.frame.size.height)];
    self.markLabel.font = [UIFont systemFontOfSize:13];
    self.markLabel.textColor = [UIColor colorWithRed:0.59 green:0.73 blue:0.41 alpha:1];
    [self.contentView addSubview:self.markLabel];
    
    self.markCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.markLabel.frame.origin.x + self.markLabel.frame.size.width + self.contentView.frame.size.width / 100, self.markLabel.frame.origin.y, self.contentView.frame.size.width / 6, self.markLabel.frame.size.height)];
    self.markCountLabel.font = [UIFont systemFontOfSize:13];
    self.markCountLabel.textColor = [UIColor colorWithRed:0.83 green:0.83 blue:0.83 alpha:1];
    [self.contentView addSubview:self.markCountLabel];
    
    self.commentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - WIDTH/3, self.markCountLabel.frame.origin.y, self.contentView.frame.size.width / 18, self.contentView.frame.size.width / 18)];
    [self.contentView addSubview:self.commentImageView];
    self.commentImageView.image = [UIImage imageNamed:@"iconfont-pinglun.png"];
    
    
    self.commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.commentImageView.frame.origin.x + self.commentImageView.frame.size.width + self.contentView.frame.size.width / 21.3, self.commentImageView.frame.origin.y, self.markCountLabel.frame.size.width, self.commentImageView.frame.size.height)];
    self.commentLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.commentLabel];
    
    
    self.likeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.commentLabel.frame.origin.x + self.commentLabel.frame.size.width, self.commentLabel.frame.origin.y, self.commentImageView.frame.size.width, self.commentImageView.frame.size.height)];
    [self.contentView addSubview:self.likeImageView];
    self.likeImageView.image = [UIImage imageNamed:@"xin-3.png"];
    
    
    
    self.likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.likeImageView.frame.origin.x + self.likeImageView.frame.size.width + self.contentView.frame.size.width / 21.3, self.likeImageView.frame.origin.y, self.commentLabel.frame.size.width, self.commentLabel.frame.size.height)];
    self.likeLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.likeLabel];
    
}


-(void)setDynDetailList:(ZZCDynamicDetailModel *)dynDetailList{
    
    _dynDetailList = dynDetailList;
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[self.dynDetailList.userinfo objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"iconfont-touxiang.png"]];
    self.nameLabel.text = [self.dynDetailList.userinfo objectForKey:@"uname"];
    self.nameLabel.frame = CGRectMake(self.headImageView.frame.origin.x + self.headImageView.frame.size.width + self.contentView.frame.size.width / 64, self.headImageView.frame.origin.y + HEIGHT / 80, self.contentView.frame.size.width / 2, self.headImageView.frame.size.height / 2);
    [self.nameLabel sizeToFit];
    
    self.timeLabel.text = self.dynDetailList.addtime_f;
    self.timeLabel.frame = CGRectMake(WIDTH - WIDTH/4, self.nameLabel.frame.origin.y, self.nameLabel.frame.size.width, self.nameLabel.frame.size.height);
    [self.timeLabel sizeToFit];
    
    self.contentLabel.text = self.dynDetailList.content;
    self.contentLabel.frame = CGRectMake(self.headImageView.frame.origin.x, self.headImageView.frame.origin.y + self.headImageView.frame.size.height + HEIGHT * 0.04, WIDTH - self.headImageView.frame.origin.x * 2, HEIGHT * 0.05);
    // 设置label的行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:self.contentLabel.text];;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:15];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.contentLabel.text.length)];
    self.contentLabel.attributedText = attributedString;
    self.contentLabel.numberOfLines = 3;
    [self.contentLabel sizeToFit];
    self.contentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    self.markImageView.frame = CGRectMake(self.contentLabel.frame.origin.x, self.contentLabel.frame.origin.y + self.contentLabel.frame.size.height + HEIGHT / 25, self.contentView.frame.size.width / 21, self.contentView.frame.size.width / 21);
    
    NSString *markStr = [NSString stringWithFormat:@"·%@", [self.dynDetailList.tag_info objectForKey:@"tag"]];
    self.markLabel.text = markStr;
    self.markLabel.frame = CGRectMake(self.markImageView.frame.origin.x + self.markImageView.frame.size.width + self.contentView.frame.size.width / 100, self.markImageView.frame.origin.y, self.contentView.frame.size.width / 5, self.markImageView.frame.size.height);
    [self.markLabel sizeToFit];
    NSString *markCountStr = [NSString stringWithFormat:@"·%@", [self.dynDetailList.tag_info objectForKey:@"count"]];
    self.markCountLabel.text = markCountStr;
    self.markCountLabel.frame = CGRectMake(self.markLabel.frame.origin.x + self.markLabel.frame.size.width + self.contentView.frame.size.width / 100, self.markLabel.frame.origin.y, self.contentView.frame.size.width / 6, self.markLabel.frame.size.height);
    [self.markCountLabel sizeToFit];
    
    self.commentImageView.frame = CGRectMake(WIDTH - WIDTH/3, self.markCountLabel.frame.origin.y, self.contentView.frame.size.width / 21.3, self.contentView.frame.size.width / 21.3);
    
    NSString *commentStr = [NSString stringWithFormat:@"%@", [self.dynDetailList.counterList objectForKey:@"comment"]];
    self.commentLabel.text = commentStr;
    self.commentLabel.frame = CGRectMake(self.commentImageView.frame.origin.x + self.commentImageView.frame.size.width + self.contentView.frame.size.width / 21.3, self.commentImageView.frame.origin.y, self.contentView.frame.size.width / 12, self.commentImageView.frame.size.height);
    
    self.likeImageView.frame = CGRectMake(self.commentLabel.frame.origin.x + self.commentLabel.frame.size.width, self.commentLabel.frame.origin.y, self.commentImageView.frame.size.width, self.commentImageView.frame.size.height);
    
    NSString *likeStr = [NSString stringWithFormat:@"%@", [self.dynDetailList.counterList objectForKey:@"like"]];
    self.likeLabel.text = likeStr;
    self.likeLabel.frame = CGRectMake(self.likeImageView.frame.origin.x + self.likeImageView.frame.size.width + self.contentView.frame.size.width / 21.3, self.likeImageView.frame.origin.y, self.commentLabel.frame.size.width, self.commentLabel.frame.size.height);
    
    
}


#pragma mark - 自定义高度方法
+ (CGFloat)heightForContent:(NSString *) content{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0],NSFontAttributeName, nil];//NSFontAttributeName 是key   [UIFont systemFontOfSize:] 是value
    CGSize size = CGSizeMake(WIDTH - WIDTH/10, 10000);
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
